﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace asscope.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //// เปิด session เพื่อเตรียมทำงานกับ Database
            NHibernate.ISession session = asscope.core.NHibernateHelper.GetCurrentSession();
            // ใช้งาน transaction 
            //NHibernate.ITransaction tx = session.BeginTransaction();


            // ทำการสร้าง customer instance
            //asscope.core.DomainEntities.sample cust1 = new asscope.core.DomainEntities.sample();
            
           // cust1.firstname = "Somchai";
            //cust1.lastname = "Sakleoi";
            //cust1.Sex = Vol1.Sample01.MyDAL.DomainEntities.Sex.Male;
            //cust1.Age = 25;
            /*
            // ทำการสร้าง address ของ customer
            Vol1.Sample01.MyDAL.DomainEntities.Address addr = new Vol1.Sample01.MyDAL.DomainEntities.Address();
            addr.Road = "Ratchada";
            addr.City = "Huaykwang";
            addr.Country = "Thailand";
            addr.PostCode = "10310";

            // เพิ่ม address ให้ customer
            cust1.Addresses.Add(addr);
            */

            // สั่ง Save ลง Database
            //session.Save(cust1);

            //session.Save(cust1);

            var res = session.CreateCriteria(typeof(asscope.core.DomainEntities.sample)).Add(NHibernate.Criterion.Restrictions.Like("firstname", "a%")).List<asscope.core.DomainEntities.sample>();

            Console.WriteLine(" Search customer by FirstName 'Som%' found {0} object ", res.Count);
            foreach (var customer in res)
            {
                //Console.WriteLine("customer firstname={0} lastname={1}", customer.firstname, customer.lastname);
                Console.WriteLine("xxxxxx");
            }


            // สั่งให้ commit transaction
           // tx.Commit();
            // สั่งปิด Session
            asscope.core.NHibernateHelper.CloseSession();
            Console.ReadKey();

        }
    }
}
